/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  io.idc.core.log.publisher.MagicLogPublisher
 *  org.springframework.stereotype.Component
 *  org.stringtemplate.v4.ST
 */
package com.chenfan.magic.resolver;

import com.chenfan.magic.core.IdcEngineEntry;
import com.chenfan.magic.core.MagicLogPublisher;
import com.chenfan.magic.entity.TTLDetailModel;
import org.springframework.stereotype.Component;
import org.stringtemplate.v4.ST;

import java.util.Map;

/**
 * @author lm
 */
@Component
public class ST4Resolver
implements __IResolver {
    public static final String TYPE_CODE = "st4";

    @Override
    public String resolve(Map<String, Object> idcRuntimePool, String templateContent, Map<String, Object> paramMap) {
        TTLDetailModel ttlDetailModel = new TTLDetailModel();
        ttlDetailModel.start();
        String result = "";
        try {
            ST template = new ST(templateContent);
            for (Map.Entry<String, Object> kv : paramMap.entrySet()) {
                String key = kv.getKey();
                Object value = kv.getValue();
                template.add(key, value);
            }
            result = template.render();
            MagicLogPublisher.publishResolverEvent((String)TYPE_CODE, (String)templateContent, (String)result, paramMap, (String)(ttlDetailModel.end().getTtl() + ""));
        }
        catch (Exception e) {
            e.printStackTrace();
            MagicLogPublisher.publishResolverEvent((String)TYPE_CODE, (String)templateContent, (String)result, paramMap, (String)(ttlDetailModel.end().getTtl() + ""), (Throwable)e);
            IdcEngineEntry.throwException(idcRuntimePool, null, e);
        }
        return result;
    }
}

